﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CourseSystem.Stat
{
    public class UrlStat
    {
        public static Dictionary<int, UrlStatInfo> StudentUrlStatDic;
        public static Dictionary<int, UrlStatInfo> TeacherUrlStatDic;

        static UrlStat()
        {
            StudentUrlStatDic = new Dictionary<int, UrlStatInfo>();
            TeacherUrlStatDic = new Dictionary<int, UrlStatInfo>();
        }

        /// <summary>
        /// 更新统计信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="url"></param>
        public static void UpdateStuUrlStat(int id, string url)
        {
            url = url.ToLower();
            var now = DateTime.Now;
            //新来的统计信息
            if (!StudentUrlStatDic.ContainsKey(id))
            {
                StudentUrlStatDic.Add(id, new UrlStatInfo { Url = url, StartViewTime = now, LastUpdateTime = now });
            }
            else
            {
                var info = StudentUrlStatDic[id];
                if (info.Url == url)
                    info.LastUpdateTime = now;
                else
                {
                    //地址发生变更

                }
            }
        }

        public static void UpdateTeaUrlStat(int id,string url)
        {
            
        }

        /// <summary>
        /// 保鲜
        /// </summary>
        /// <param name="id"></param>
        public static void RemainStuFlash(int id)
        {
            UrlStatInfo info = null;
            if (StudentUrlStatDic.TryGetValue(id, out info))
            {
                info.LastUpdateTime = DateTime.Now;
            }
        }

        /// <summary>
        /// 保鲜
        /// </summary>
        /// <param name="id"></param>
        public static void RemainTeaFlash(int id)
        {
            UrlStatInfo info = null;
            if (TeacherUrlStatDic.TryGetValue(id, out info))
            {
                info.LastUpdateTime = DateTime.Now;
            }
        }
    }
}
